//gcc -fpic -shared -o libfolderwatch.dylib folderwatch.c
package com.silvtar.util;

import com.silvtar.sync.model.SSTrigger;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

public class FolderMonitor extends Thread{
    
    boolean launch = false;
    
    public interface CLibrary extends Library {
       
        CLibrary INSTANCE = (CLibrary) Native.loadLibrary(Platform.isMac()? "folderwatch" : "folderwatch", CLibrary.class);
        void start_monitor(String path, long sec);
    }
    
    String path;
    long sec;
    SSTrigger ssTrigger;
    
    public FolderMonitor(SSTrigger ssTrigger, String path, long sec) {
        this.ssTrigger = ssTrigger;
        this.path = path;
        this.sec = sec;
    }
    
    public void run() {
        launch = true;
        while (launch) {
            CLibrary.INSTANCE.start_monitor(path, sec);
            ssTrigger.monitorRun();
        }
    }
}
